package middle

import (
	"gitee.com/injoyai/goutil/chans"
	"github.com/gogf/gf/net/ghttp"
)

type RequestLimit struct {
	*chans.Limit
}

func NewRequestLimit(limit int) *RequestLimit {
	return &RequestLimit{
		Limit: chans.NewLimit(limit),
	}
}

func (this *RequestLimit) Middle(r *ghttp.Request) {
	if err := this.Do(); err != nil {
		r.Response.SetBuffer([]byte("操作过于频率"))
		r.ExitAll()
	}
	r.Middleware.Next()
	this.Done()
}
